package com.mallcai.bigdata.ladon.dpl.mapper.common;

import com.mallcai.bigdata.ladon.dpl.entity.common.Datasource;
import com.mallcai.bigdata.ladon.dpl.mapper.common.provider.DatasourceSqlProvider;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

import static com.mallcai.bigdata.ladon.dpl.mapper.common.provider.DatasourceSqlProvider.TB_DATASOURCE;

/**
 * @author gst
 * @date 2019-12-30 20:36
 */
@Repository
public interface DatasourceMapper {

    @InsertProvider(type = DatasourceSqlProvider.class, method = "insert")
    int insert(Datasource ds);

    @UpdateProvider(type = DatasourceSqlProvider.class, method = "update")
    int update(Datasource ds);

    @Update({
            "UPDATE " + TB_DATASOURCE + " SET archive = 1, modified = unix_timestamp(now()), modified_by=#{modifiedBy} WHERE id = #{id}"
    })
    int delete(Datasource ds);

    @Select({
            "SELECT * FROM " + TB_DATASOURCE + " WHERE id = #{datasourceId}"
    })
    Datasource getById(@Param("datasourceId") Long datasourceId);

    @SelectProvider(type = DatasourceSqlProvider.class, method = "getByParams")
    List<Datasource> getByParams(@Param("params") Map<String, Object> params);
}
